﻿using System;
using com.cruxomatic.controllers;
using com.cruxomatic.controllers.Administration;
using com.cruxomatic.DTOs;
using com.cruxomatic.security;

public partial class Controls_Common_LoggedInUserCompany : System.Web.UI.UserControl
{
    SessionData sessionData = new SessionData();
    UserInformation userInformation;

    protected void Page_Load(object sender, EventArgs e)
    {
        userInformation = sessionData.CurrentUser;
        CurrentUserController controller = new CurrentUserController();
        sessionData = new SessionData();
        ICruxSecurityManager cruxSecurityManager = CruxSecurityManagerFactory.GetSecurityManager();
        int numberofcompanies = cruxSecurityManager.GetCompaniesForUser(sessionData.CurrentUser.UserID).Count;
        if (numberofcompanies > 1) { lblCompany.Visible = false; lnkCompany.Visible = true; }
        else { lblCompany.Visible = true; lnkCompany.Visible = false; }
        lblCompany.Text = Company;
        lnkCompany.Text = Company;
    }

    public string Company
    {
        get
        {
            SessionData sessiondata = new SessionData();
            if (sessiondata.CurrentCompany == null)
                return userInformation.CompanyName;
            else
                return sessiondata.CurrentCompany.CompanyName;
        }
    }
    protected void lnkCompany_Click(object sender, EventArgs e)
    {
        NavigationController.OpenView("ChangeYourCompany");
    }
}
